<?php
!defined('ADMIN') && exit('Not allowed to directly view page');
	require_once(DEDEINC.'/datalistcp.class.php');
	if($dopost == 'add')
	{
		// 没选定上传文件，0 文件类型不允许, -2 保存失败，其它：返回上传后的文件名
		$upfile = AdminUpload('photo');
		$msg ='';
		if($upfile=='-1')
		{
			$msg = "<script language='javascript'>
					alert('你没指定要上传的文件或文件大小超过限制！');
				</script>";
		}
		else if($upfile=='-2')
		{
			$msg = "<script language='javascript'>
					alert('上传文件失败，请检查原因！');
				</script>";
		}
		else if($upfile=='0')
		{
			$msg = "<script language='javascript'>
					alert('文件类型不正确！');
				</script>";
		}
		if($msg){ echo $msg;exit;}
		$dsql->ExecuteNoneQuery("insert into `#@__hospital` (name,addr,time,phone,yid,ifcheck,seo,keyword,keyword_description,digest,intro,photo,recommend,link)
			values( '$name','$addr','$time','$phone','$yid','0','$seo','$keyword','$keyword_description','$digest','$intro','$upfile','$recommend','$link')");
		showmsg('添加信息成功',"?do=ask_hospital");
	}
	else if($dopost == 'save')
	{
		$id = (int)$id;
		if(!empty($_FILES['photo']['name'])){
			$upfile = AdminUpload('photo');
			$msg ='';
			if($upfile=='-1')
			{
				$msg = "<script language='javascript'>
						alert('你没指定要上传的文件或文件大小超过限制！');
					</script>";
			}
			else if($upfile=='-2')
			{
				$msg = "<script language='javascript'>
						alert('上传文件失败，请检查原因！');
					</script>";
			}
			else if($upfile=='0')
			{
				$msg = "<script language='javascript'>
						alert('文件类型不正确！');
					</script>";
			}
			$file= "photo='$upfile',";
		}
		$dsql->ExecuteNoneQuery("update  `#@__hospital` set $file name='$name',addr='$addr',
		time='$time',phone='$phone',yid='$yid',ifcheck='0',seo='$seo',keyword='$keyword',keyword_description='$keyword_description',digest='$digest',intro='$intro',recommend='$recommend',`link`='$link' where id=$id");
		showmsg('修改信息成功',"?do=ask_hospital");
	}
	else if($action == 'delete' && $id)
	{
		$id = (int)$id;
		$dsql->ExecuteNoneQuery("delete from `#@__hospital` where id=$id");
		showmsg('删除信息成功',"?do=ask_hospital");
	}
	else
	{
		if($action == 'update' && $id)
		{
			$id = (int)$id;
			$hospital = $dsql->getone('Select * From `#@__hospital` where id='.$id);
			$sql = "Select * From `#@__sys_enum` where egroup like 'nativeplace' order by disorder asc, evalue asc";
			$dlist = new DataListCP();
			$dlist->SetTemplet(DEDEADMIN.'/templets/ask_hospital_add.htm');
			$dlist->SetSource($sql);
			$dlist->display();
			exit();
		}
		else
		{
			$sql = "Select * From `#@__sys_enum` where egroup like 'nativeplace' order by disorder asc, evalue asc";
			$dlist = new DataListCP();
			$dlist->SetTemplet(DEDEADMIN.'/templets/ask_hospital_add.htm');
			$dlist->SetSource($sql);
			$dlist->display();
			exit();
		}
	}


?>